package com.zm.cc;

import com.google.gson.Gson;
import com.zm.cc.service.BizException;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Utils {
    public static void check(boolean bool,String msg) throws BizException {
        if (bool){
            throw new BizException(msg);
        }
    }

   public static void checkEmpty(Object object,String msg) throws BizException {
        check(object == null ||
                object instanceof String && ((String)object).isBlank(),msg);
    }

    public  static void print(HttpServletResponse resp, Object object) throws IOException {
        Gson gson = new Gson();
        String json = gson.toJson(object);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().println(json);
    }


}
